<template>
  <div class="contheader">
    <router-link to="/"><span>您好！欢迎来到梧桐时代</span></router-link>
    <!--<router-link to="/Entry"><span v-show="logina">登录</span></router-link>-->
    <!--<router-link to="/Myaddress"><span v-show="!logina">{{username}}</span></router-link>-->
    <!--<span v-show="!logina" @click="tuichu">退出</span>-->
    <!--<router-link to="/Login" v-show="logina"><span>免费注册</span></router-link>-->
    <ul>
      <router-link to="/Entry"><li v-show="logina">登录</li></router-link>
      <li v-show="!logina">{{username}}</li>
      <li v-show="!logina" @click="tuichu">退出</li>
      <li class="lisnpor"></li>
      <router-link to="/Login" v-show="logina"><li>免费注册</li></router-link>
      <li class="lisnpor" style="width:0;"></li>
      <li @click="debgg()">我的梧桐</li>
      <li class="lisnpor" style="width:0;"></li>
      <!--<router-link to="/Shoppingcart"> <li class="gwc">购物车0</li></router-link>-->
      <!--<li>购物车</li>-->
      <!--<a href="http://www.wutongsd.com">-->
        <!--<li>关注梧桐</li>-->
      <!--</a>-->
      <!--&lt;!&ndash;<router-link to="/Details"><li>帮助中心</li></router-link>&ndash;&gt;-->
      <!--<router-link to="">-->
        <!--<li @click="addFavorite2()">收藏本站</li>-->
      <!--</router-link>-->
      <!--<a href="http://www.wutongsd.com/backManage">-->
        <li class="sjzx" @click="backgo()" @mouseenter="enter3($event)" @mouseleave="leave3($event)">商家中心</li>
      <!--</a>-->
    </ul>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        login: false,
        logina: true,
        username: ''
      }
    },
    methods: {
      backgo(){
        this.$message.error('商家入驻请联系梧桐时代');
      },
      debgg(){
        if (this.getCookie('login')) {
          this.logina = false
          this.$router.push({path: '/Myaddress'})
        }else{
          this.logina = true
          sessionStorage.clear()
          //清除cookie
          this.setCookie("login", "", -1);
          this.$router.push({path: '/Entry',query: {redirect:'/Myaddress'}})
        }
      },
      setCookie: function (cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays * 60 * 1000));
        var expires = "expires=" + d.toUTCString();
        console.info(cname + "=" + cvalue + "; " + expires);
        document.cookie = cname + "=" + cvalue + "; " + expires;
        console.info(document.cookie);
      },
      //获取cookie
      getCookie: function (cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') c = c.substring(1);
          if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
        }
        return "";
      },
      //清除cookie
      clearCookie: function () {
        this.setCookie("username", "", -1);

      },
      tuichu () {
        let that=this
        $.ajax({
          type: "GET",
          url: local+"/awm/user/loginOut",
          dataType: "json",
          success: function(data){
            console.log(1121212)
            that.logina = true
            sessionStorage.clear()
            //清除cookie
            that.setCookie("login", "", -1);
            that.$router.push({path:'/Tenderhallhome'})

          }
        });
      },
      clickTip: function () {
        if (!this.login) {
          this.$router.push({path:'/Register'})
        }
      },
      enter3: function (e) {
        $('.shangjia').show()

      },
      leave3: function (e) {
        $('.shangjia').hide()
      },
      enter4: function (e) {
        $(e.currentTarget).show()
        $('.sjzx').addClass('activesa')
      },
      leave4: function (e) {
        $(e.currentTarget).hide()
        $('.sjzx').removeClass('activesa')
      },
      addFavorite2 () {
        var url = window.location
        var title = document.title
        var ua = navigator.userAgent.toLowerCase()
        if (ua.indexOf('360se') > -1) {
          alert('由于360浏览器功能限制，请按 Ctrl+D 手动收藏！')
        }
        else if (ua.indexOf('msie 8') > -1) {
          window.external.AddToFavoritesBar(url, title) //IE8
        }
        else if (document.all) {
          try {
            window.external.addFavorite(url, title)
          } catch (e) {
            alert('您的浏览器不支持,请按 Ctrl+D 手动收藏!')
          }
        }
        else if (window.sidebar) {
          window.sidebar.addPanel(title, url, '')
        }
        else {
          alert('您的浏览器不支持,请按 Ctrl+D 手动收藏!')
        }
      }
    },
    mounted: function () {
      this.username = sessionStorage.getItem('userName')
      if (sessionStorage.getItem('login')) {
        this.logina = false
      }

    }
  }
</script>

<style scoped>
  .contheader {
    width: 100%;
    height: 40px;
    background: #dcdcdc;
  }

  .contheader span {
    width: 20%;
    height: 40px;
    line-height: 40px;
    float: left;
    color: #4b4b4b;
  }

  /*.header span:hover {*/
    /*color: red;*/
    /*cursor: pointer;*/
    /*background: #ffffff;*/
  /*}*/

  .contheader ul {
    width: 50%;
    height: 40px;
    float: right;
    line-height: 40px;
    position: relative;
    text-align: right;
    padding-right:60px;
  }

  .contheader ul li {
    width: 15%;
    height: 40px;
    line-height: 40px;
    display: inline-block;
    color: black;
    text-align: center;
    vertical-align: top;
    margin:0 -3px;
  }

  .contheader ul li:nth-child(6) {
    width: 20%;
  }

  .contheader ul li:hover {
    color: red;
    cursor: pointer;
    background: #ffffff;
  }

  /*.header ul .shangjia {*/
    /*width: 130px;*/
    /*height: 150px;*/
    /*background: #eeeeee;*/
    /*position: absolute;*/
    /*top: 50px;*/
    /*left: 73%;*/
    /*display: none;*/
  /*}*/

  .contheader ul .shangjia p:hover {
    cursor: pointer;
    background: #ffffff;
    color: red;
  }

  .activesa {
    background: #ffffff;
    color: red;
  }

  .ddps {
    position: absolute;
    left: 0;
    top: 30px;
  }

  .contheader ul .lisnpor{
    display: inline-block;
    width: 0;
    height: 14px;
    line-height: 14px;
    vertical-align: top;
    position: relative;
    top: 6px;
    left: 0;
    font-size: 0;
    border-left: 1px solid #ccc;
    margin: 10px  0 0;

  }
</style>
